package autotest;

import java.io.File;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.junit.Test;

import com.youku.util.XMLHelper;

@SuppressWarnings("unchecked")
public class XmlHelperTester {
	
	@Test
	public void t() throws DocumentException{
		Element root=getRoot("E:/project/workspace/autotest/src/main/resources/autotest.xml");
		
		Element g=(Element) root.element("project").element("variables").elements("global").get(6);		
		String value=
				XMLHelper.value(g, "value");
//				g.attributeValue("value");
		
//		Assert.assertEquals(value, );
		print(value);
	}
	
	@Test
	public void t1() throws Exception{
		Element root=getRoot("E:/project/workspace/autotest/src/main/resources/part1.xml");
		
		Element e=(Element) ((Element)root.elements("testsuite").get(0)).elements("reftemp").get(0);
		
		List<Element> list=e.elements("param");

		print(list.size());
	}
	
	void print(Object o){
		System.out.println(o);
	}

	public static Element getRoot(String location) throws DocumentException {
		SAXReader s=new SAXReader();
		Document d=s.read(new File(location));
		return d.getRootElement();
	}
	
}
